package com.qdlc.p2p.manage.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.BondService;
import com.qdlc.p2p.biz.service.BondTenderService;
import com.qdlc.p2p.biz.service.BorrowConfigService;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.dto.BorrowConfig;
import com.qdlc.p2p.dal.model.BondModel;
import com.qdlc.p2p.dal.model.BondTenderModel;

public class ManageBondAction  extends BaseAction<BondModel> implements ModelDriven<BondModel> {
	
	@Resource
	private BondService bondService;
	@Resource
	private BondTenderService bondTenderService;
	@Resource
	private BorrowConfigService borrowConfigService;

	private Map<String, Object> data;
	
	/**
	 * 债权页面
	 * @return String
	 * @throws Exception
	 *             if has error
	 */
	@Action("/modules/loan/bond/bondManager")
	public String bondManager() throws Exception {
		List<BorrowConfig> borrowConfigList = borrowConfigService.findAll();
		request.setAttribute("borrowConfigList", borrowConfigList);
		return "bondManager";
	}

	/**
	 * 债权列表
	 * @throws Exception
	 *             if has error
	 */
	@Action("/modules/loan/bond/bondList")
	public void bondList() throws Exception {
		data = new HashMap<String, Object>();
		PageDataList<BondModel> list = bondService.getBondList(model);
		data.put("total", list.getPage().getTotal());
		data.put("rows", list.getList());
		printJson(getStringOfJpaObj(data));
	}
	
	/**
	 * 债权投资记录页面
	 * @return String
	 * @throws Exception
	 *             if has error
	 */
	@Action("/modules/loan/bond/bondTenderRecordPage")
	public String bondTenderRecordPage() throws Exception {
		return "bondTenderRecordPage";
	}
	/**
	 * 债权投资记录数据
	 * @return String
	 * @throws Exception
	 *             if has error
	 */
	@Action("/modules/loan/bond/bondTenderRecord")
	public void bondTenderRecord() throws Exception {
		// 债权转让记录
		BondTenderModel bondTenderModel = new BondTenderModel();
		bondTenderModel.setBondId(model.getId());
		bondTenderModel.setUuid(model.getUuid());
		PageDataList<BondTenderModel> bondTenderList = bondTenderService.getTenderModelPage(bondTenderModel);
		data = new HashMap<String, Object>();
		data.put("rows", bondTenderList.getList());
		data.put("total", bondTenderList.getPage());
		printWebJson(getStringOfJpaObj(data));
	}
}
